package com.cysion.study.presenter

import com.cysion.study.ktbox.base.BasePresenter
import com.cysion.study.ktbox.net.BaseResponseRx
import com.cysion.other.addTo
import com.cysion.targetfun._subscribe
import com.cysion.study.helper.UserCache
import com.cysion.study.net.ApiClient
import com.cysion.study.ui.iview.TeacherView

/**
 * Created by chu on 2019-06-30.
 */
class TeacherPresenter : BasePresenter<TeacherView>() {
    //获取课程
    fun getCousel() {
        checkViewAttached()
        attchedView?.loading()
        ApiClient.api.getCourse(UserCache.token).compose(BaseResponseRx.validateToMain())._subscribe {
            _onNext {
                attchedView?.onGetCourse(it)
                attchedView?.stopLoad()
            }
            _onError {
                error(it)
                attchedView?.stopLoad()
                attchedView?.onGetCourseError("getCousel")
            }
        }.addTo(compositeDisposable)
    }

    fun getCouselMonth() {
        checkViewAttached()
        attchedView?.loading()
        ApiClient.api.getMonth(UserCache.token).compose(BaseResponseRx.validateToMain())._subscribe {
            _onNext {
                attchedView?.onGetCourse(it)
                attchedView?.stopLoad()
            }
            _onError {
                error(it)
                attchedView?.stopLoad()
                attchedView?.onGetCourseError("getCousel")
            }
        }.addTo(compositeDisposable)
    }
    fun getCouselAll() {
        checkViewAttached()
        attchedView?.loading()
        ApiClient.api.getCourseAll(UserCache.token).compose(BaseResponseRx.validateToMain())._subscribe {
            _onNext {
                attchedView?.onGetCourse(it)
                attchedView?.stopLoad()
            }
            _onError {
                error(it)
                attchedView?.stopLoad()
                attchedView?.onGetCourseError("getCousel")
            }
        }.addTo(compositeDisposable)
    }
}